import { useMemo } from "react";

export type IRoute = {
  name: string;
  key: string;
  text?: string;
  // 当前页是否展示面包屑
  breadcrumb?: boolean;
  children?: IRoute[];
  // 当前路由是否渲染菜单项，为 true 的话不会在菜单中显示，但可通过路由地址访问。
  ignore?: boolean;
  actionId?: string; // 权限code
  componentPath?: string;
  element?: ()=>void;
};

export const routes: IRoute[] = [
  
  {
    name: "menu.echarts",
    key: "echarts",
    text:'能耗大数据',
    children: [
      // {
      //   name: "menu.echarts.cost",
      //   text:'数据概览',
      //   key: "echarts/cost",
      //   componentPath: "echarts/cost",
      //   element: () => import("./pages/charts/cost/Cost"),
      // },
      {
        name: "menu.echarts.view",
        text:'数据看板',
        key: "echarts/view",
        componentPath: "echarts/view",
        element: () => import("./pages/charts/view"),
      }
    ],
  },
  
  {
    name: "menu.power",
    key: "power",
    text: '能耗数据管理',
    children: [
      {
        name: "menu.power.list",
        key: "power/list",
        text: '一车间能耗数据',
        componentPath: "power/list",
        element: () => import("./pages/power/list/index"),
      },
      {
        name: "menu.power.workshop",
        key: "power/workshop",
        text: '一车间能耗',
        componentPath: "power/workshop",
        element: () => import("./pages/power/workshop/index"),
      },
      {
        name: "menu.power.table",
        key: "power/table",
        text: '一车间数据报表',
        componentPath: "power/table",
        element: () => import("./pages/power/table/index"),
      }
    ],
  },
  {
    name: "menu.pollution",
    key: "pollution",
    text: '污染物管理',
    children: [
      {
        name: "menu.pollution.list",
        key: "pollution/list",
        text: '一车间污水排放',
        componentPath: "system/user",
        element: () => import("./pages/pollution/index"),
      },
    ],
  },
  {
    name: "menu.forcast",
    key: "forcast",
    text: '能耗预测管理',
    children: [
      {
        name: "menu.forcast.list",
        key: "forcast/list",
        text: '一车间能耗预测',
        componentPath: "forcast/list",
        element: () => import("./pages/forcast/index"),
      },
    ],
  },
  {
    name: "menu.system",
    key: "system",
    text: '系统管理',
    children: [
      {
        name: "menu.system.user",
        key: "system/user",
        text: '用户设置',
        componentPath: "system/user",
        element: () => import("./pages/system/index"),
      },
    ],
  },
];

const useRoute = ():[IRoute[],string]=>{
    const defaultRoute = useMemo(()=>{
        const first = routes?.length ? routes[0] : null;
        if(first){
            const firstRoute = first.children?.[0]?.key || first.key;
            return firstRoute;
        }
        return ''
    },[routes])
    return [routes,defaultRoute]
}

export default useRoute;
